/**
 * <p>Title: MaterialCodeRestImpl</p>
 * <p>Description: The class of MaterialCodeRest implement </p>
 * <p>Copyright: Shanghai Batchsight Pharmaceutical Technologies, Inc. Copyright(c) 2016</p>
 * @author Chen Wei
 * @version 1.0
 * <pre>Histroy:
 *       2016-12-14  Chen Wei  Create
 *</pre>
*/
package cn.jhg.account.rest;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import cn.jhg.account.entity.MaterialCode;
import cn.jhg.account.service.MaterialCodeSvc;
import cn.jhg.account.util.ServiceResult;
@Component
public class MaterialCodeRestImpl implements MaterialCodeRest {
	@Resource
	private MaterialCodeSvc materialCodeSvc;
	
	/**
	 * 新增原料编码
	 * @param code	编码
	 * @param name	编码名
	 * @param spec	编码说明
	 * @param typeId	类型ID
	 * @param propId	属性Object ID
	 * @param valid		true or false
	 * @return	原料编码id 和 errorCode
	 */
	@Override
	public ServiceResult<Integer> addCode(String code, String name, String spec, int typeId, String propId,
			boolean valid) {
		MaterialCode materialCode=new MaterialCode();
		materialCode.setCode(code);
		materialCode.setName(name);
		materialCode.setSpec(spec);
		materialCode.setTypeId(typeId);
		materialCode.setTypeId(typeId);
		materialCode.setValid(valid);
		ServiceResult<Integer> result=materialCodeSvc.addCode(materialCode, 100, 0);
		return result;
	}
	
	/**
	 * 删除原料编码
	 * @param id	原料编码ID
	 * @return		ErrorCode
	 */
	@Override
	public ServiceResult<Integer> deleteCode(int id) {
		ServiceResult<Integer> result=materialCodeSvc.deleteCode(id, 100, 0);
		return result;
	}
	
	/**
	 * 修改原料编码
	 * @param id	原料编码ID
	 * @param code	编码
	 * @param name	编码名
	 * @param spec	编码说明
	 * @param typeId	类型ID
	 * @param propId	属性Object ID
	 * @param valid		true or false
	 * @return 			ErrorCode
	 */
	@Override
	public ServiceResult<Integer> updateCode(int id, String code, String name, String spec, int typeId, String propId,
			boolean valid) {
		MaterialCode materialCode=new MaterialCode();
		materialCode.setId(id);
		materialCode.setCode(code);
		materialCode.setName(name);
		materialCode.setSpec(spec);
		materialCode.setTypeId(typeId);
		materialCode.setTypeId(typeId);
		materialCode.setValid(valid);
		ServiceResult<Integer> result=materialCodeSvc.updateCode(materialCode, 100, 0);
		return result;
	}

	/**
	 * 根据编码查找原料
	 * @param code 原料编码
	 * @return	MaterialCode实体 和 ErrorCode
	 */
	@Override
	public ServiceResult<MaterialCode> queryByCode(String code) {
		ServiceResult<MaterialCode> result=materialCodeSvc.queryByCode(code, 0);
		return result;
	}

	/**
	 * 根据编码id查找原料
	 * @param id 原料编码id
	 * @return	MaterialCode实体 和 ErrorCode
	 */
	@Override
	public ServiceResult<MaterialCode> queryById(String id) {
		ServiceResult<MaterialCode> result=materialCodeSvc.queryByCode(id, 0);
		return result;
	}

	/**
	 * 查找原料
	 * @param id 原料编码id
	 * @return	MaterialCode实体 和 ErrorCode
	 */
	@Override
	public ServiceResult<List<MaterialCode>> findCodeDetail(String code, String name, String spec, int typeId) {
		ServiceResult<List<MaterialCode>> result=materialCodeSvc.findCodeDetail(code,name,spec,typeId, 0);
		return result;
	}
	
	/**
	 * 失效原料编码
	 * @param id	原料编码ID
	 * @return 			ErrorCode
	 */
	@Override
	public ServiceResult<Integer> invalidCode(int id) {
		ServiceResult<Integer> result=materialCodeSvc.invalidCode(id,100, 0);
		return result;
	}

	/**
	 * 查询产品
	 * @param str  包含code、name的字符串
	 * @return 	ServiceResult<List<MaterialCode>>	MaterialCode集合,ErrorCode
	 */
	@Override
	public ServiceResult<List<MaterialCode>> findMaterialCodeDetail(String str) {
		int typeId = 4;//bom的类型id
		ServiceResult<List<MaterialCode>> result = materialCodeSvc.findMaterialCodeDetail(typeId,str);
		return result;
	}

	@Override
	public ServiceResult<List<MaterialCode>> findMaterialCodeDetails(String str) {
		ServiceResult<List<MaterialCode>> result =materialCodeSvc.findMaterialCodeDetails(str);
		return result;
	}
	

}
